package net.dntuan.training.spring.integration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;

/**
 * @author tuan.dangnhu
 * 
 * $LastChangedRevision: 122 $
 * $LastChangedDate: 2014-10-06 03:05:04 +0000 (Mon, 06 Oct 2014) $
 * $LastChangedBy: dnhutuan@gmail.com $
 */
public class CustomFilter {

  private static Logger LOGGER = LoggerFactory.getLogger(CustomFilter.class);

  @Autowired
  private ApplicationContext appContext;

  /**
   * Only accept the message that starts with the letter 'H'.
   *
   * @param message
   * @return
   */
  public boolean accept(Message message) {
    EventDrivenConsumer uppercaseServiceActivator = appContext.getBean("uppercaseServiceActivator",
        EventDrivenConsumer.class);
    LOGGER.info("Status of service: " + uppercaseServiceActivator.isRunning() + " "
        + uppercaseServiceActivator.hashCode());
    return message.getContent().toUpperCase().startsWith("H") && uppercaseServiceActivator.isRunning();
  }
}
